package action

import (
	"core/coreentity"
	"core/coreservice"
	"core/corestruct"
	"core/coreutil"
	"core/myerrors"
	"ht/htinfo"
	"reflect"
)

type DeleteAction struct {
}

func (p *DeleteAction) Do(mm *corestruct.IdModel, ctx *corestruct.HttpContext) (int64, error) {
	var m = &coreentity.HtCls{
		Id: mm.Id,
	}
	tx := coreservice.BaseService.Delete(m, ctx.DB)
	if tx.Error != nil {
		return 0, myerrors.NewByErr(tx.Error)
	}
	return tx.RowsAffected, nil
}

func DeleteActionInit() {
	var mact = &DeleteAction{}
	var maction = corestruct.Action{
		Method: "",

		FullUrl: URLPrev + "/delete",
		Name:    "删除" + PAGEName,
		Ename:   "",
		Memo:    "",

		PinType:    "",
		PinIslist:  false,
		PoutType:   "",
		PoutIslist: false,
		PoutIspage: false,

		AuthType: corestruct.AuthType_AUTH,

		LogNeed:     true,
		LogPin:      true,
		LogPout:     true,
		LogTemplete: "",

		PrjName: htinfo.PRJ_NAME,

		Value: reflect.ValueOf(mact),
	}
	coreutil.ActionUtil.Add(maction)

}
